-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix for fmt::printf on Power9 architecture with the XL compiler #3256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR but looks like it doesn't work in some CI configs. Also since this is a workaround for printf it's better putting it there (i.e. initialize members in printf_arg_formatter
's ctor).
Thanks @vitaut. Since the (I think) I resolved the error with |
Upstreamed to fmt: fmtlib/fmt#3256
Please submit a bug report to IBM and also could you post the error here for future reference? |
Thanks @vitaut -- I've created a simple reproducer and will submit to IBM. Description of the error:The code in In case it helps, here's the stacktrace from gdb:
|
include/fmt/format.h
Outdated
arg_formatter(buffer_appender<Char> it, const format_specs<Char>& s) | ||
: out(it), specs(s) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor is redundant, please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround for gcc-4.8.
#3256 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed that.
I wonder if there is a cleaner workaround that doesn't involve introducing redundant ctors. Would using a function that constructs auto make_arg_formatter(OutputIt iter, format_specs<Char>& s) -> arg_formatter {
return {iter, s, locale_ref()}
}
printf_arg_formatter(OutputIt iter, format_specs<Char>& s, context_type& ctx)
: base(make_arg_formatter(iter, s), context_(ctx) {} Then we can keep the workaround localized to where the compiler bug occurs. |
Thanks @vitaut Would you like me to rework it using the above suggestion? |
Yes, please. Using a "factory" function is cleaner because it will allow us to keep the reference while still keeping the workaround localized to printf implementation. |
Thanks for the suggestion @vitaut -- I think we're getting there! |
include/fmt/format.h
Outdated
static auto make_arg_formatter(iterator iter, format_specs<Char>& s) | ||
-> arg_formatter { | ||
return {iter, s, locale_ref()}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this function to printf.h
where it is used (it doesn't need to be in arg_formatter
) and add a comment that it is a workaround for the XL compiler bug, with a link to the bug report if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Unfortunately, the IBM ticket is not publicly accessible.
This avoids the need to pass a temporary (default) locale_ref.
Per PR suggestion.
Use this within printf_arg_formatter constructor as workaround for XL compiler bug that optimizes away base class initializer. Also: Reverts conversion of internal `specs` variable back to a const ref Per PR suggestion.
Per PR suggestion.
Merged, thanks. Please comment here once you know which version of the XL compiler fixes the issue. |
Thanks -- will do. |
I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.
This PR works around a bug encountered with the IBM xl compiler on the Power9 architecture (e.g. on the Lassen supercomputer ) with
fmt::printf()
.The issue appears to be that XL is not copying the
format_specs
struct in theprintf_arg_formatter
constructor to thearg_formatter
base class.fmt/include/fmt/printf.h
Lines 237 to 238 in a73a9b6
This was causing the
printf
tests to segfault. E.g.fmt/test/printf-test.cc
Line 73 in a73a9b6
I resolved the problem by adding an explicit constructor to the
arg_formatter
base class.This regression appears to have been introduced between
[email protected]
and[email protected]
.I tested this using the following compiler/config options
Note: There are a few other failing tests with this compiler. I will post separate issues for them.